<?php
class Office extends CI_Model {
	var $OrgIntro = "";
	var $OrgName = "";

    function __construct()
    {
        parent::__construct();
    }
	    
    function get_last_n_entries($num=10)
    {
        $query = $this->db->order_by('OrgId', 'desc');
		$query = $query->get('webpage_office', $num);
        return $query->result();
    }
	
	function get_entries($limit, $offset)
    {
        $query = $this->db->order_by('OrgId', 'desc');
		$query = $query->get('webpage_office', $limit, $offset);
        return $query->result();
    }
	
	function get_entrie($id)
    {
        $query = $this->db->where('OrgId', $id);
		$query = $query->get('webpage_office');
        return $query->result();
    }
	
	function get_total_num()
	{
		return $this->db->count_all_results('webpage_office');
	}

    function insert_entry()
    {
        $this->OrgName = $this->input->post('title');
		$this->OrgIntro = $this->input->post('p-detail');
        return $this->db->insert('webpage_office', $this);
    }

    function update_entry()
    {
		$this->OrgName = $this->input->post('title');
		$this->OrgIntro = $this->input->post('p-detail');
		$id = $this->input->post('id');
		$table = 'webpage_office';
        $this->db->update($table, $this, array('OrgId' => $id));
    }
	
	function delete_entries()
    {		
		$entries = $this->input->post('delete');
		$table = 'webpage_office';
		
		foreach ($entries as $entry) {
			$this->db->delete($table, array('OrgId' => $entry));
		}
    }
}